package com.wy;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.ollama.OllamaChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.URI;

/**
 * @author 33117
 * @version 1.0
 * @data 2025/6/9 21:58
 */
@SpringBootTest
public class Langchain4J {

    @Test
    public void test() {
        OpenAiChatModel model = OpenAiChatModel.builder()
                .baseUrl("http://langchain4j.dev/demo/openai/v1")
                .apiKey("demo")
                .modelName("gpt-4o-mini")
                .build();
        String answer = model.chat("你是谁");
        System.out.println(answer);
    }

    @Resource
    private OpenAiChatModel openAiChatModel;

    @Test
    public void test2() {
        String chatted = openAiChatModel.chat("我是谁");
        System.out.println(chatted);
    }

    @Resource
    private OllamaChatModel ollamaChatModel;

    @Test
    public void test3() {
        // deepseek
        String chatted = ollamaChatModel.chat("你是谁");
        System.out.println(chatted);
    }

    @Resource
    private QwenChatModel qwenChatModel;

    @Test
    public void test4() {
        // 千问
        String chatted = qwenChatModel.chat("你是谁");
        System.out.println(chatted);
    }

    @Test
    public void test5() {
        WanxImageModel wanxImageModel = WanxImageModel.builder()
                .modelName("wanx2.1-t2i-plus")
                .apiKey("sk-ddee004b353342fc8183f989a656dbf2")
                .build();
        Response<Image> response = wanxImageModel.generate("一个笑脸");
        URI url = response.content().url();
        System.out.println(url);
    }
}
